<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
		<title>富文本编辑器</title>
		<link rel="stylesheet" href="../../component/layui/css/layui.css" />
		<link href="../../admin/css/pearCommon.css" rel="stylesheet" />
		<style>
			body {
				margin: 10px;
			}
		</style>
	</head>
	<body class="layui-bg-gray">
		<div class="layui-card">
			<div class="layui-card-header">富文本编辑器</div>
			<div class="layui-card-body">
				<form class="layui-form" action="">
					<div class="layui-form-item">
						<label class="layui-form-label">文章名称</label>
						<div class="layui-input-inline">
							<input type="text" name="wzlName" placeholder="" id="wzlName" class="layui-input">
						</div>
						<label class="layui-form-label">文章顺序</label>
		                <div class="layui-input-inline">
		                    <input type="checkbox" name="write" title="置顶">
		                </div>
		                <label class="layui-form-label">标签</label>
		              	<div class="layui-input-inline" >
						 	<select id="city" name="city"></select>
						</div>  
						<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="edit-save">
							<i class="layui-icon layui-icon-search"></i>
							保存
						</button>
						<button type="reset" class="pear-btn pear-btn-md">
							<i class="layui-icon layui-icon-refresh"></i>
							重置
						</button>
<!-- 						<button type="reset" class="pear-btn pear-btn-md"> -->
<!-- 							<i class="layui-icon layui-icon-refresh"></i> -->
<!-- 							重置 -->
<!-- 						</button> -->
					</div>
		            <div class="layui-form-item">
		            	<textarea name="" id="edit" cols="30" rows="10"></textarea>
		            </div>
				</form>
				
<!-- 				<div class="layui-btn-group" style="margin-top: 10px"> -->
<!-- 					<button class="layui-btn" lay-event="getContent">获取内容</button> -->
<!-- 				</div> -->
			</div>
		</div>

		<script src="../../component/layui/layui.js"></script>
		<script>
			layui.use(['form','tinymce', 'util', 'layer', 'jquery'], function() {
				  var form = layui.form;
				var tinymce = layui.tinymce;
				var $ = layui.jquery;


				var util = layui.util;

				var edit = tinymce.render({
					elem: "#edit",
					height: 400
				});

				$.get(
					//1 异步提交的urL
				    '/layman/article/queryBQ',
				    //3 访问后成功的回调函数
				    function (data) {
				        if (data) {
				        	var vp ="<option value=''>无标签</option> "
				        	for(var i=0; i<data.data.length;i++){
				        		vp += "<option value='"+data.data[i].groupName+"'>"+data.data[i].groupName+"</option>"
				        	}
				        	$("#city").append(vp);
		                    layui.form.render("select");//重新渲染 固定写法
				        }else{
				            layer.msg("获取标签失败！", {icon: 1});
				        }
				    }
				);
				
// 				util.event('lay-event', {
// 					getContent: function() {
// 						console.log(edit.getContent())
// 						layer.msg("展开控制台查看")
// 						console.log($("#wzlName").val())
// 					}
// 				});

			  //监听提交
			  form.on('submit(edit-save)', function(data){
				  console.log(data.field.write)
				  var isTreue = 1;
				  if(data.field.write !== 'no' && data.field.write !== undefined){
					  isTreue = 0;
				  }
				  var city = "";
				  if(data.field.city != null){
					  city = data.field.city;
				  }
				  $.post(
						    //1 异步提交的urL
						    '/layman/article/save',
						    //2 form表单以键值对形式传输
						    {"taile": edit.getContent(),"wzlName" :data.field.wzlName,"write" :isTreue, "city" :data.field.city},
						    //3 访问后成功的回调函数
						    function (data) {
					            alert(data.state > 0);
						        if (data.state > 0) {
						            layer.msg("添加成功！", {icon: 1});
						            
						        }else{
						            layer.msg("添加失败！", {icon: 1});

						        }

						    }

						);

				 
				  
			    return false;
			  });


			});
		</script>
	</body>
</html>
